<template>
  <el-container v-loading.fullscreen.lock="loading">
    <!-- 侧边栏 -->
    <el-aside width="auto">
      <SideBar />
    </el-aside>
    <el-container :class="'main-container ' + isHide">
      <!-- 导航栏 -->
      <el-header height="84px" class="navCss" :style="$store.state.theme.head">
        <NavBar :key="$route.fullPath" />
      </el-header>
      <!-- 内容 -->
      <el-main :style="$store.state.theme.body">
        <div class="fade-transform-box">
          <transition name="fade-transform" mode="out-in">
            <router-view :key="$route.fullPath" />
          </transition>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import NavBar from "./NavBar";
import SideBar from "./SideBar";
export default {
  components: {
    NavBar,
    SideBar
  },
  computed: {
    loading(){
      return this.$store.state.loading
    },
    isHide() {
      return this.$store.state.collapse ? "hideSideBar" : "";
    }
  },
  created() {
    //浏览器刷新函数
    window.addEventListener('beforeunload', () => {
      //刷新保存标签
      sessionStorage.setItem("tabList",JSON.stringify(this.$store.state.tabList))
    })
  },
  // destroyed() {
  //   window.removeEventListener('beforeunload', () => {
  //   })
  // }
};
</script>

<style scoped>
.navCss{
  padding:0
}

.main-container {
  transition: margin-left 0.45s;
  margin-left: 210px;
  min-height: 100vh;
}
.hideSideBar {
  margin-left: 64px;
}
.fade-transform-enter-active,
.fade-transform-leave-active {
  transition: all 0.5s ease 0s;
}
.fade-transform-enter {
  opacity: 0;
  transform: translateX(-30px);
}
.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
.fade-transform-box {
  position: relative;
  top: 0px;
  bottom: 0px;
  width: 100%;
  overflow: hidden;
}
</style>
